#import "TCMPassInfoModel.h"
#import <objc/runtime.h>

@implementation TCMPassInfoModel

+ (void)load
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _model = [[self alloc] init];
    });
}

static TCMPassInfoModel * _model;
+ (instancetype)sharedModel
{
    return _model;
}

+ (void)addPropertyWithKey:(NSString *)key value:(id)value modifier:(TCMModifierType)modifier
{
    const char * cKey = key.UTF8String;
    objc_setAssociatedObject(_model, cKey, value, [self getPolicyWithClassStr:modifier]);
}

+ (id)getPropertyWithKey:(NSString *)key
{
    const char * cKey = key.UTF8String;
    return objc_getAssociatedObject(_model, cKey) ? objc_getAssociatedObject(_model, cKey) : nil;
}

+ (objc_AssociationPolicy)getPolicyWithClassStr:(TCMModifierType)modifier
{
    switch (modifier) {
        case TCMModifierTypeCopy:
            return OBJC_ASSOCIATION_COPY_NONATOMIC;
        case TCMModifierTypeStrong:
            return OBJC_ASSOCIATION_RETAIN_NONATOMIC;
        case TCMModifierTypeAssign:
            return OBJC_ASSOCIATION_ASSIGN;
        case TCMModifierTypeWeak:
            return OBJC_ASSOCIATION_ASSIGN;
    }
    return OBJC_ASSOCIATION_RETAIN_NONATOMIC;
}

@end
